// 点击去登录
qs('.login a').onclick = function(){
    qs('.login').style.display = 'none'
    qs('.register').style.display = 'block'
}


// 点击去注册
qs('.register a').onclick = function(){
    qs('.login').style.display = 'block'
    qs('.register').style.display = 'none'
}


// 注册功能
qs('.register form').addEventListener('submit',function(e){
    e.preventDefault()
    const username = qs('.register input[name="username"]').value.trim()
    
    const password = qs('.register input[name="password"]').value.trim()
    if(!username||!password) return alert('用户名或密码不能为空')
    
    const data = `username=${username}&password=${password}`
axios.post('http://www.itcbc.com:8000/api/register',data).then(({data:res})=>{
    console.log('注册接口返回的结果',res);
    alert(res.message)
    if(res.code === 0){
        qs('.login').style.display = 'block'
        qs('.register').style.display = 'none' 
       
    }
 })
})




// axios.post('http://www.itcbc.com:8000/api/register',{
//     username,
//     password
// }).then(res=>{
//     console.log(res);
// })


// 登录功能
qs('.login form').addEventListener('submit',function(e){
    e.preventDefault()
    const username = qs('.register input[name="username"]').value.trim()
    
    const password = qs('.register input[name="password"]').value.trim()
    if(!username||!password) return alert('用户名或密码不能为空')
    
    const data = `username=${username}&password=${password}`
axios.post('http://www.itcbc.com:8000/api/login',data).then(({data:res})=>{
    console.log('注册接口返回的结果',res);
    alert(res.message)
    if(res.code === 0){
        location.href = './index.html'
       
    }
 })
})